# 简化测试：只用弹性材料，检查GPU求解器基本功能

wipe
model basic -ndm 2 -ndf 2

# 定义材料 - 使用简单弹性材料
nDMaterial ElasticIsotropic 1 30.0e9 0.2

# 创建一个4x4的小网格
set nx 4
set ny 4
set lx 4.0
set ly 4.0
set dx [expr $lx / $nx]
set dy [expr $ly / $ny]

# 创建节点
set nodeTag 1
for {set j 0} {$j <= $ny} {incr j} {
    for {set i 0} {$i <= $nx} {incr i} {
        set x [expr $i * $dx]
        set y [expr $j * $dy]
        node $nodeTag $x $y
        incr nodeTag
    }
}

# 创建单元
set elemTag 1
for {set j 0} {$j < $ny} {incr j} {
    for {set i 0} {$i < $nx} {incr i} {
        set n1 [expr $j * ($nx + 1) + $i + 1]
        set n2 [expr $n1 + 1]
        set n3 [expr $n1 + ($nx + 1) + 1]
        set n4 [expr $n1 + ($nx + 1)]
        element quad $elemTag $n1 $n2 $n3 $n4 1.0 PlaneStress 1
        incr elemTag
    }
}

# 固定底部
for {set i 1} {$i <= [expr $nx + 1]} {incr i} {
    fix $i 1 1
}

# 施加顶部载荷
timeSeries Linear 1
pattern Plain 1 1 {
    set topLoad -1000.0
    set numTopNodes [expr $nx + 1]
    for {set i [expr ($ny) * ($nx + 1) + 1]} {$i <= [expr ($ny + 1) * ($nx + 1)]} {incr i} {
        load $i 0.0 [expr $topLoad / $numTopNodes]
    }
}

# 使用GPU求解器
system GPUSolver

constraints Plain
numberer RCM
test NormDispIncr 1.0e-6 20 0
algorithm Linear
integrator LoadControl 1.0
analysis Static

puts "开始弹性材料测试 (4x4网格, Linear算法)..."
set ok [analyze 1]
if {$ok == 0} {
    puts "✓ 弹性分析成功收敛"
    set topNode [expr ($ny + 1) * ($nx + 1)]
    set disp [nodeDisp $topNode 2]
    puts "顶部中心节点位移: $disp m"
} else {
    puts "✗ 分析失败，返回码: $ok"
}

wipe
